/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DialogInventarisDetail.java
 *
 * Created on 30 Okt 12, 9:12:45
 */
package sistemperpustakaan.view.buku;

import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import sistemperpustakaan.controller.BukuController;
import sistemperpustakaan.controller.InventarisController;
import sistemperpustakaan.entity.Buku;
import sistemperpustakaan.entity.Inventaris;
import sistemperpustakaan.utility.UserUtility;

/**
 *
 * @author EKo
 */
public class DialogInventarisDetail extends javax.swing.JDialog {

    InventarisController controller;
    boolean isAddNew;
    private Integer idStatus = 0;
    Inventaris inventaris;

    /** Creates new form DialogBukuDetail */
    public DialogInventarisDetail(java.awt.Frame parent, boolean modal, InventarisController controller) {
        super(parent, modal);
        this.controller = controller;
        initComponents();
        setLocationRelativeTo(controller.getInventarisView());
        setAction();
        controller.setInventarisDetail(this);
        isAddNew = true;
        buttonSelectBuku.requestFocus();
        controller.showGenerateIdInventaris();
        setTitle("Tambah Inventaris Buku");
        buttonSave.setEnabled(UserUtility.privilege[UserUtility.INSERT_UPDATE_DELETE]);
        txtStatus.setText(idStatus.toString());
        comboStatus.setSelectedIndex(0);
    }

    public DialogInventarisDetail(java.awt.Frame parent, boolean modal, InventarisController controller, String id) {
        super(parent, modal);
        this.controller = controller;
        initComponents();
        setLocationRelativeTo(controller.getInventarisView());
        setAction();
        controller.setInventarisDetail(this);
        this.controller.showDetailInventaris(id);
        isAddNew = false;
        buttonSelectBuku.requestFocus();
        setTitle("Detail Inventaris Buku");
        buttonSave.setEnabled(UserUtility.privilege[UserUtility.INSERT_UPDATE_DELETE]);
        comboStatus.setSelectedIndex(Integer.parseInt(txtStatus.getText()));
    }

    public final void setAction() {


        buttonSelectBuku.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                SelectBuku sb = new SelectBuku(controller.getInventarisView().getFrameMain(), true, controller);
                Point p = txtIdBuku.getLocationOnScreen();
                p.setLocation(p.getX(), p.getY() + 28);
                sb.setLocation(p);
                sb.setVisible(true);
            }
        });
        comboStatus.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                idStatus = Integer.valueOf(comboStatus.getSelectedIndex());
                selectStatus();
            }
        });
        buttonSave.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (isAddNew) {
                    controller.saveNewInventaris();
                } else {
                    controller.saveUpdateInventaris();
                }
            }
        });
        buttonCancel.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
    }

    public void selectStatus() {
        if (comboStatus.getSelectedIndex() == 0) {
            idStatus = 0;
            txtStatus.setText("0");
        } else if (comboStatus.getSelectedIndex() == 1) {
            idStatus = 1;
            txtStatus.setText("1");
        } else {
            idStatus = 2;
            txtStatus.setText("2");
        }
    }

    public JButton getButtonCancel() {
        return buttonCancel;
    }

    public void setButtonCancel(JButton buttonCancel) {
        this.buttonCancel = buttonCancel;
    }

    public JButton getButtonSave() {
        return buttonSave;
    }

    public void setButtonSave(JButton buttonSave) {
        this.buttonSave = buttonSave;
    }

    public JTextField getTxtIdBuku() {
        return txtIdBuku;
    }

    public void setTxtIdBuku(JTextField txtIdBuku) {
        this.txtIdBuku = txtIdBuku;
    }

    public JTextField getTxtIdInventaris() {
        return txtIdInventaris;
    }

    public void setTxtIdInventaris(JTextField txtIdInventaris) {
        this.txtIdInventaris = txtIdInventaris;
    }

    public JTextField getTxtStatus() {
        return txtStatus;
    }

    public void setTxtStatus(JTextField txtStatus) {
        this.txtStatus = txtStatus;
    }

    public JComboBox getComboStatus() {
        return comboStatus;
    }

    public void setComboStatus(JComboBox comboStatus) {
        this.comboStatus = comboStatus;
    }

    public JTextField getTxtJudul() {
        return txtJudul;
    }

    public void setTxtJudul(JTextField txtJudul) {
        this.txtJudul = txtJudul;
    }

    public Integer getIdStatus() {
        return idStatus;
    }

    public void setIdStatus(Integer idStatus) {
        this.idStatus = idStatus;
    }

    public JTextField getTxtNoPanggil() {
        return txtNoPanggil;
    }

    public void setTxtNoPanggil(JTextField txtNoPanggil) {
        this.txtNoPanggil = txtNoPanggil;
    }

    public JTextField getTxtPengarang() {
        return txtPengarang;
    }

    public void setTxtPengarang(JTextField txtPengarang) {
        this.txtPengarang = txtPengarang;
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel11 = new javax.swing.JLabel();
        gbr = new javax.swing.JLabel();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        Status = new javax.swing.JLabel();
        txtStatus = new javax.swing.JTextField();
        buttonSelectBuku = new javax.swing.JButton();
        comboStatus = new javax.swing.JComboBox();
        txtJudul = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        txtNoPanggil = new javax.swing.JTextField();
        txtPengarang = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtIdInventaris = new javax.swing.JTextField();
        txtIdBuku = new javax.swing.JTextField();
        buttonCancel = new javax.swing.JButton();
        buttonSave = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel11.setText("Data Detail Inventaris Buku Perpustakaan");

        gbr.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sistemperpustakaan/image/inventaris.png"))); // NOI18N

        jTabbedPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jPanel3.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel13.setText("ID Buku");
        jPanel3.add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, 68, -1));

        jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel14.setText("ID Inventaris");
        jPanel3.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, 71, -1));

        Status.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        Status.setText("Status");
        jPanel3.add(Status, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 174, 58, -1));

        txtStatus.setEditable(false);
        txtStatus.setEditable(false);
        jPanel3.add(txtStatus, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 171, 36, -1));

        buttonSelectBuku.setText("...");
        jPanel3.add(buttonSelectBuku, new org.netbeans.lib.awtextra.AbsoluteConstraints(269, 42, 30, -1));

        comboStatus.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tersedia", "Terpinjam", "Hilang" }));
        jPanel3.add(comboStatus, new org.netbeans.lib.awtextra.AbsoluteConstraints(159, 171, -1, -1));

        txtJudul.setEditable(false);
        jPanel3.add(txtJudul, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 78, 352, -1));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel1.setText("Judul");
        jPanel3.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 80, 89, -1));

        txtNoPanggil.setEditable(false);
        jPanel3.add(txtNoPanggil, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 109, 202, -1));

        txtPengarang.setEditable(false);
        jPanel3.add(txtPengarang, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 140, 436, -1));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel2.setText("No Panggil");
        jPanel3.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 110, 68, -1));

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel3.setText("Pengarang");
        jPanel3.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 140, -1, -1));
        jPanel3.add(txtIdInventaris, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 11, 162, -1));
        jPanel3.add(txtIdBuku, new org.netbeans.lib.awtextra.AbsoluteConstraints(117, 43, 142, -1));

        jTabbedPane1.addTab("Inventaris", jPanel3);

        buttonCancel.setText("Cancel");

        buttonSave.setText("Save");
        buttonSave.setToolTipText("Save");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 654, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(gbr)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel11))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(buttonSave, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(buttonCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jLabel11))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(gbr, javax.swing.GroupLayout.PREFERRED_SIZE, 112, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 313, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonSave)
                    .addComponent(buttonCancel))
                .addGap(16, 16, 16))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel Status;
    private javax.swing.JButton buttonCancel;
    private javax.swing.JButton buttonSave;
    private javax.swing.JButton buttonSelectBuku;
    private javax.swing.JComboBox comboStatus;
    private javax.swing.JLabel gbr;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField txtIdBuku;
    private javax.swing.JTextField txtIdInventaris;
    private javax.swing.JTextField txtJudul;
    private javax.swing.JTextField txtNoPanggil;
    private javax.swing.JTextField txtPengarang;
    private javax.swing.JTextField txtStatus;
    // End of variables declaration//GEN-END:variables
}
